package expandingproject;

import static expandingproject.ExpandingProject.correct;
import static expandingproject.ExpandingProject.incorrect;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author Inderpreet
 */
public class MathPractice {

    public String getTestType() {
        Scanner keyb = new Scanner(System.in);
        try {
            System.out.println("What test would you like?");
            System.out.println("1) (A)ddition");
            System.out.println("2) (M)ultiplication");
            System.out.println("3) (S)ubtraction");
            String testType = keyb.nextLine();
            if (testType.equalsIgnoreCase("Addition") || testType.equalsIgnoreCase("A") || testType.equals("1")) {
                return "Addition";
            } else if (testType.equalsIgnoreCase("Multiplication") || testType.equalsIgnoreCase("M") || testType.equals("2")) {
                return "Multiplication";
            } else if (testType.equalsIgnoreCase("Subtraction") || testType.equalsIgnoreCase("S") || testType.equals("3")) {
                return "Subtraction";
            } else {
                return "N";
            }
        } catch (Exception b) {
            System.out.println("Not a valid option");
        }
        return "";
    }

    public int setNumberOfQuestions() {
        Scanner keyb = new Scanner(System.in);
        System.out.println("How many questions would you like?");
        int questions = Integer.parseInt(keyb.nextLine());
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        return questions;
    }

    public void performTest(int questions, String testType) {
        Scanner keyb = new Scanner(System.in);
        Random rand = new Random();
        int answer = 0;
        for (int i = 0; i < questions; i++) {
            try {
                if (testType.equalsIgnoreCase("Addition")) {
                    int number = rand.nextInt(100) + 1;
                    int number2 = rand.nextInt(50) + 1;
                    answer = number + number2;
                    System.out.print(number + "+" + number2 + "= ");
                } else if (testType.equalsIgnoreCase("Multiplication")) {
                    int number = rand.nextInt(10) + 1;
                    int number2 = rand.nextInt(10) + 1;
                    answer = number * number2;
                    System.out.print(number + "x" + number2 + "= ");
                } else {
                    int number = rand.nextInt(100) + 1;
                    int number2 = rand.nextInt(50) + 1;
                    answer = number - number2;
                    System.out.print(number + "-" + number2 + "= ");
                }
                int userAnswer = Integer.parseInt(keyb.nextLine());
                if (answer == userAnswer) {
                    System.out.println("Correct!");
                    System.out.println("~~~~~~~~");
                    correct++;
                } else {
                    System.out.println("Incorrect!");
                    System.out.println("Correct answer: " + answer);
                    System.out.println("~~~~~~~~~~~~~~~~~~");
                    incorrect++;
                }
            } catch (Exception e) {
                System.out.println("Not a number");
                System.out.println("Incorrect!");
                System.out.println("Correct answer: " + answer);
                System.out.println("~~~~~~~~~~~~~~~~~~");
                incorrect++;
            }
        }
    }

    public void printResults(int questions, long startTime) {
        System.out.println("Results for a " + questions + " question test");
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println("Correct: " + correct);
        System.out.println("Incorrect: " + incorrect);
        double percent = ((correct * 100.00) / questions);
        System.out.format("Percent: " + "%.2f", percent);
        System.out.println("%");
        long endTime = System.currentTimeMillis();
        long totalTime = (endTime - startTime) / 1000;
        System.out.println("Average time per question: "
                + (totalTime / questions) + " seconds");
        System.out.println("Total time taken: " + (totalTime / 60)
                + " minutes and " + (totalTime % 60) + " seconds");
    }

    public String testOver() {
        Scanner keyb = new Scanner(System.in);
        System.out.println("Play Again?(y/n)");
        if (keyb.nextLine().equalsIgnoreCase("y")) {
            return "y";
        } else {
            return "n";
        }
    }
}